/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    ap-northeast-2-pop = 'actiontrail.ap-northeast-1.aliyuncs.com',
    cn-beijing-finance-1 = 'actiontrail.aliyuncs.com',
    cn-beijing-finance-pop = 'actiontrail.aliyuncs.com',
    cn-beijing-gov-1 = 'actiontrail.aliyuncs.com',
    cn-beijing-nu16-b01 = 'actiontrail.aliyuncs.com',
    cn-edge-1 = 'actiontrail.aliyuncs.com',
    cn-fujian = 'actiontrail.aliyuncs.com',
    cn-haidian-cm12-c01 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-finance = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'actiontrail.aliyuncs.com',
    cn-hangzhou-test-306 = 'actiontrail.aliyuncs.com',
    cn-hongkong-finance-pop = 'actiontrail.aliyuncs.com',
    cn-qingdao-nebula = 'actiontrail.aliyuncs.com',
    cn-shanghai-et15-b01 = 'actiontrail.aliyuncs.com',
    cn-shanghai-et2-b01 = 'actiontrail.aliyuncs.com',
    cn-shanghai-inner = 'actiontrail.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'actiontrail.aliyuncs.com',
    cn-shenzhen-finance-1 = 'actiontrail.aliyuncs.com',
    cn-shenzhen-inner = 'actiontrail.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'actiontrail.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'actiontrail.aliyuncs.com',
    cn-wuhan = 'actiontrail.aliyuncs.com',
    cn-yushanfang = 'actiontrail.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'actiontrail.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'actiontrail.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'actiontrail.aliyuncs.com',
    eu-west-1-oxs = 'actiontrail.ap-northeast-1.aliyuncs.com',
    rus-west-1-pop = 'actiontrail.ap-northeast-1.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('actiontrail', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateTrailRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  roleName?: string(name='RoleName'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model CreateTrailResponseBody = {
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  param?: string(name='Param'),
  result?: string(name='Result'),
  roleName?: string(name='RoleName'),
}

model CreateTrailResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateTrailResponseBody(name='body'),
}

async function createTrailWithOptions(request: CreateTrailRequest, runtime: Util.RuntimeOptions): CreateTrailResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateTrail',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createTrail(request: CreateTrailRequest): CreateTrailResponse {
  var runtime = new Util.RuntimeOptions{};
  return createTrailWithOptions(request, runtime);
}

model DeleteTrailRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  name?: string(name='Name'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model DeleteTrailResponseBody = {
  param?: string(name='Param'),
  result?: string(name='Result'),
}

model DeleteTrailResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DeleteTrailResponseBody(name='body'),
}

async function deleteTrailWithOptions(request: DeleteTrailRequest, runtime: Util.RuntimeOptions): DeleteTrailResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DeleteTrail',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function deleteTrail(request: DeleteTrailRequest): DeleteTrailResponse {
  var runtime = new Util.RuntimeOptions{};
  return deleteTrailWithOptions(request, runtime);
}

model DescribeTrailsRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  name?: string(name='Name'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model DescribeTrailsResponseBody = {
  param?: string(name='Param'),
  result?: string(name='Result'),
  trailList?: string(name='TrailList'),
}

model DescribeTrailsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DescribeTrailsResponseBody(name='body'),
}

async function describeTrailsWithOptions(request: DescribeTrailsRequest, runtime: Util.RuntimeOptions): DescribeTrailsResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DescribeTrails',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function describeTrails(request: DescribeTrailsRequest): DescribeTrailsResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeTrailsWithOptions(request, runtime);
}

model EchoRequest {
  bucketName?: string(name='BucketName'),
  format?: string(name='Format'),
  help?: string(name='Help'),
  isLogging?: string(name='IsLogging'),
  keyPrefix?: string(name='KeyPrefix'),
  latestDeliveryError?: string(name='LatestDeliveryError'),
  latestDeliveryTime?: string(name='LatestDeliveryTime'),
  name?: string(name='Name'),
  startLoggingTime?: string(name='StartLoggingTime'),
  status?: string(name='Status'),
  stopLoggingTime?: string(name='StopLoggingTime'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model EchoResponseBody = {
  param?: string(name='Param'),
  result?: string(name='Result'),
  requestId?: string(name='requestId'),
}

model EchoResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: EchoResponseBody(name='body'),
}

async function echoWithOptions(request: EchoRequest, runtime: Util.RuntimeOptions): EchoResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'Echo',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function echo(request: EchoRequest): EchoResponse {
  var runtime = new Util.RuntimeOptions{};
  return echoWithOptions(request, runtime);
}

model GetTrailStatusRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  name?: string(name='Name'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model GetTrailStatusResponseBody = {
  isLogging?: boolean(name='IsLogging'),
  latestDeliveryError?: string(name='LatestDeliveryError'),
  latestDeliveryTime?: string(name='LatestDeliveryTime'),
  param?: string(name='Param'),
  result?: string(name='Result'),
  startLoggingTime?: string(name='StartLoggingTime'),
  stopLoggingTime?: string(name='StopLoggingTime'),
}

model GetTrailStatusResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetTrailStatusResponseBody(name='body'),
}

async function getTrailStatusWithOptions(request: GetTrailStatusRequest, runtime: Util.RuntimeOptions): GetTrailStatusResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTrailStatus',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTrailStatus(request: GetTrailStatusRequest): GetTrailStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTrailStatusWithOptions(request, runtime);
}

model HelpRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model HelpResponseBody = {
  action?: string(name='Action'),
  param?: string(name='Param'),
  result?: string(name='Result'),
}

model HelpResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: HelpResponseBody(name='body'),
}

async function helpWithOptions(request: HelpRequest, runtime: Util.RuntimeOptions): HelpResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'Help',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function help(request: HelpRequest): HelpResponse {
  var runtime = new Util.RuntimeOptions{};
  return helpWithOptions(request, runtime);
}

model LookupEventsRequest {
  endTime?: string(name='EndTime'),
  event?: string(name='Event'),
  eventAccessKeyId?: string(name='EventAccessKeyId'),
  eventName?: string(name='EventName'),
  eventRW?: string(name='EventRW'),
  eventType?: string(name='EventType'),
  format?: string(name='Format'),
  help?: string(name='Help'),
  maxResults?: string(name='MaxResults'),
  nextToken?: string(name='NextToken'),
  request?: string(name='Request'),
  resourceName?: string(name='ResourceName'),
  resourceType?: string(name='ResourceType'),
  serviceName?: string(name='ServiceName'),
  startTime?: string(name='StartTime'),
  type?: string(name='Type'),
  user?: string(name='User'),
  version?: string(name='Version'),
}

model LookupEventsResponseBody = {
  endTime?: string(name='EndTime'),
  events?: string(name='Events'),
  nextToken?: string(name='NextToken'),
  param?: string(name='Param'),
  requestId?: string(name='RequestId'),
  result?: string(name='Result'),
  startTime?: string(name='StartTime'),
}

model LookupEventsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: LookupEventsResponseBody(name='body'),
}

async function lookupEventsWithOptions(request: LookupEventsRequest, runtime: Util.RuntimeOptions): LookupEventsResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'LookupEvents',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function lookupEvents(request: LookupEventsRequest): LookupEventsResponse {
  var runtime = new Util.RuntimeOptions{};
  return lookupEventsWithOptions(request, runtime);
}

model StartLoggingRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  name?: string(name='Name'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model StartLoggingResponseBody = {
  param?: string(name='Param'),
  result?: string(name='Result'),
}

model StartLoggingResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: StartLoggingResponseBody(name='body'),
}

async function startLoggingWithOptions(request: StartLoggingRequest, runtime: Util.RuntimeOptions): StartLoggingResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'StartLogging',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function startLogging(request: StartLoggingRequest): StartLoggingResponse {
  var runtime = new Util.RuntimeOptions{};
  return startLoggingWithOptions(request, runtime);
}

model StopLoggingRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  name?: string(name='Name'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model StopLoggingResponseBody = {
  param?: string(name='Param'),
  result?: string(name='Result'),
}

model StopLoggingResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: StopLoggingResponseBody(name='body'),
}

async function stopLoggingWithOptions(request: StopLoggingRequest, runtime: Util.RuntimeOptions): StopLoggingResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'StopLogging',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function stopLogging(request: StopLoggingRequest): StopLoggingResponse {
  var runtime = new Util.RuntimeOptions{};
  return stopLoggingWithOptions(request, runtime);
}

model UpdateTrailRequest {
  format?: string(name='Format'),
  help?: string(name='Help'),
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  roleName?: string(name='RoleName'),
  type?: string(name='Type'),
  version?: string(name='Version'),
}

model UpdateTrailResponseBody = {
  name?: string(name='Name'),
  ossBucketName?: string(name='OssBucketName'),
  ossKeyPrefix?: string(name='OssKeyPrefix'),
  param?: string(name='Param'),
  result?: string(name='Result'),
  roleName?: string(name='RoleName'),
}

model UpdateTrailResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpdateTrailResponseBody(name='body'),
}

async function updateTrailWithOptions(request: UpdateTrailRequest, runtime: Util.RuntimeOptions): UpdateTrailResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.format)) {
    query['Format'] = request.format;
  }
  if (!Util.isUnset(request.help)) {
    query['Help'] = request.help;
  }
  if (!Util.isUnset(request.name)) {
    query['Name'] = request.name;
  }
  if (!Util.isUnset(request.ossBucketName)) {
    query['OssBucketName'] = request.ossBucketName;
  }
  if (!Util.isUnset(request.ossKeyPrefix)) {
    query['OssKeyPrefix'] = request.ossKeyPrefix;
  }
  if (!Util.isUnset(request.roleName)) {
    query['RoleName'] = request.roleName;
  }
  if (!Util.isUnset(request.type)) {
    query['Type'] = request.type;
  }
  if (!Util.isUnset(request.version)) {
    query['Version'] = request.version;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UpdateTrail',
    version = '2015-09-28',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateTrail(request: UpdateTrailRequest): UpdateTrailResponse {
  var runtime = new Util.RuntimeOptions{};
  return updateTrailWithOptions(request, runtime);
}

